﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using WebAppHappyNewYear.Filter;
using WebInterface;

namespace WebAppHappyNewYear.Controllers
{
    public class FifthController : Controller
    {
        private readonly ILogger<FifthController> _logger;
        private readonly ITestServiceA _testServiceA;
        private readonly ITestServiceB _testServiceB;
        private readonly ITestServiceC _testServiceC;
        private readonly ITestServiceD _testServiceD;
        private readonly ITestServiceE _testServiceE;
        private readonly IA _ia;

        public FifthController(ILogger<FifthController> logger,
            ITestServiceA testServiceA,
            ITestServiceB testServiceB,
            ITestServiceC testServiceC,
            ITestServiceD testServiceD,
            ITestServiceE testServiceE,
            IA ia)
        {
            _logger = logger;
            _testServiceA = testServiceA;
            _testServiceB = testServiceB;
            _testServiceC = testServiceC;
            _testServiceD = testServiceD;
            _testServiceE = testServiceE;
            _ia = ia;
        }

        [CustomActionFilter2Attribute(Order =2)]
        [CustomResultFilter]
        [CustomActionFilter200Attribute(Order = 1)]
        [CustomResourseFilterAttribute]
        public IActionResult Index()
        {
            Console.WriteLine("This is Fifth Index action");
            _logger.LogInformation("This is Fifth Index action");
            return View();
        }


        [CustomActionFilter2Attribute(Order = 1)]
        [CustomResultFilter]
        [CustomActionFilter200Attribute(Order = 2)]
        public IActionResult Test_1()
        {
            Console.WriteLine("This is Fifth Test_1 action");
            _logger.LogInformation("This is Fifth Test_1 action");
            return View();
        }

        [CustomCacheResourseFilterAttribute]
        public IActionResult Test_2()
        {
            base.ViewData["ControllerActionTime"] = DateTime.Now.ToString("yy-MM-dd HH:mm:ss fff");

            Console.WriteLine("This is Fifth Test_2 action");
            _logger.LogInformation("This is Fifth Test_2 action");

            //base.ViewData["ServiceActionTime"] = _ia.Plus(3, 4);
            return View();
        }

        public IActionResult Test_3()
        {
            base.ViewData["ControllerActionTime"] = DateTime.Now.ToString("yy-MM-dd HH:mm:ss fff");

            Console.WriteLine("This is Fifth Test_3 action");
            _logger.LogInformation("This is Fifth Test_3 action");

            base.ViewData["ServiceActionTime"] = _ia.Plus(3, 4).ToString("yy-MM-dd HH:mm:ss fff");
            return View();
        }

        //[ResponseCache(Duration =60)]
        public IActionResult Test_4()
        {
            base.HttpContext.Response.Headers["Cache-Control"]="public,max-age=60";


            base.ViewData["ControllerActionTime"] = DateTime.Now.ToString("yy-MM-dd HH:mm:ss fff");

            Console.WriteLine("This is Fifth Test_4 action");
            _logger.LogInformation("This is Fifth Test_4 action");

            base.ViewData["ServiceActionTime"] = _ia.Plus(3, 4).ToString("yy-MM-dd HH:mm:ss fff");
            return View();
        }

        [CustomCacheResultFilterAttribute(Duration =60)]
        public IActionResult Test_5()
        {


            base.ViewData["ControllerActionTime"] = DateTime.Now.ToString("yy-MM-dd HH:mm:ss fff");

            Console.WriteLine("This is Fifth Test_5 action");
            _logger.LogInformation("This is Fifth Test_5 action");

            base.ViewData["ServiceActionTime"] = _ia.Plus(3, 4).ToString("yy-MM-dd HH:mm:ss fff");
            return View();
        }

        [ResponseCache(Duration = 60,Location =ResponseCacheLocation.Client)]
        public IActionResult Test_6()
        {


            base.ViewData["ControllerActionTime"] = DateTime.Now.ToString("yy-MM-dd HH:mm:ss fff");

            Console.WriteLine("This is Fifth Test_6 action");
            _logger.LogInformation("This is Fifth Test_6 action");

            base.ViewData["ServiceActionTime"] = _ia.Plus(3, 4).ToString("yy-MM-dd HH:mm:ss fff");
            return View();
        }
    }
}